package com.dbh.company.buildbook.test;

import javafx.animation.FadeTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Duration;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) {
        try {
            // 加载图片
            Image image1 = new Image("https://img.ljcdn.com/test/digHuman2?ak=LV56XXCKXJ4VW7X4K2GA&exp=2592000000&ts=1695288328&sign=fbdc250a72f3d56b89943b11652e75c2");
            Image image2 = new Image("https://img.ljcdn.com/test/digHuman1?ak=LV56XXCKXJ4VW7X4K2GA&exp=2592000000&ts=1695288297&sign=e0251e5dac2285b7c72c7c34302b6eff");

            // 创建ImageView
            ImageView imageView1 = new ImageView(image1);
            ImageView imageView2 = new ImageView(image2);

            // 创建淡入淡出动画
            FadeTransition ft = new FadeTransition(Duration.millis(3000), imageView1);
            ft.setFromValue(1.0);
            ft.setToValue(0.0);
            ft.play();

            // 当动画结束时，切换图片
            ft.setOnFinished(event -> {
                imageView1.setImage(imageView1.getImage() == image1 ? image2 : image1);
                ft.playFromStart();
            });

            StackPane root = new StackPane();
            root.getChildren().add(imageView1);

            Scene scene = new Scene(root,400,400);
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}